package com.jsh.erp.controller.api;

import com.jsh.erp.datasource.entities.DepotHead;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.depotHead.DepotHeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RequestMapping("/api")
@RestController
public class DepotHeadRemoteApi {
    @Autowired
    private DepotHeadService depotHeadService;
    @Autowired
    private DepotService depotService;

    @GetMapping("/depotHead/getDepotHead")
    public DepotHead getDepotHead(@RequestParam("number") String number)throws Exception {
        return depotHeadService.getDepotHead(number);
    }

    @GetMapping("/depotHead/getDepotHeadListByAccountIds")
    List<DepotHead> getDepotHeadListByAccountIds(@RequestParam("accountIds") String[] accountIds) throws Exception {
        return depotHeadService.getDepotHeadListByIds(Arrays.stream(accountIds).collect(Collectors.joining(",")));
    }

    // 注意
    @GetMapping("/depotHead/getAccountSum")
    public BigDecimal getAccountSum(@RequestParam("id") Long id,
                                    @RequestParam("timeStr") String timeStr,
                                    @RequestParam("type") String type) throws Exception{
        return depotHeadService.getAccountSum(id, timeStr, type);
    }

    // 注意
    @GetMapping("/depotHead/getManyAccountSum")
    public BigDecimal getManyAccountSum(@RequestParam("id") Long id,
                                        @RequestParam("timeStr") String timeStr,
                                        @RequestParam("type") String type)throws Exception {
        return depotHeadService.getManyAccountSum(id, timeStr, type);
    }
}
